home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / desktop / papcw10.zip / REGRESS.PRG < prev    next >
Text File  |  1995-02-11  |  1KB  |  45 lines

  1. ; simple linear regression y = a + bx
  2. ; b = (n*sum(xy) - sum(y)*sum(x))/(n*sum(sqr(x)) - sqr((sum(x)))
  3. ; a = mean(y)-b*mean(x)
  4. ; R1  sum(x)
  5. ; R2  sum(y)
  6. ; R3  sum(sqr(x))
  7. ; R4  sum(sqr(y))
  8. ; R5  sum(x*y)
  9. ; R6  n
  10.  
  11. LBL regress
  12. ; clear registers 1-6
  13. 1.00601 0 sto
  14. LBL clear
  15. 0 rcl 0 swap sto
  16. 0 isg
  17. GTO clear
  18.  
  19. LBL dataentry
  20. PROMPT "Enter x and y: "
  21. GTO calc  ; only if a null line is entered
  22. 1 6 STO+
  23. DUP 2 STO+
  24. DUP SQR 4 STO+
  25. SWAP
  26. DUP 1 STO+
  27. DUP SQR 3 STO+
  28. * 5 STO+
  29. GTO dataentry
  30.  
  31. LBL calc ;
  32. ; calculate b = (n*sum(xy) - sum(y)*sum(x))/(n*sum(sqr(x)) - sqr((sum(x)))
  33. 6 RCL 5 RCL * 2 RCL 1 RCL * - 6 RCL 3 RCL * 1 RCL SQR - /
  34. ; calculate a = mean(y)-b*mean(x)
  35. 2 RCL 6 RCL / OVER 1 RCL 6 RCL / * -
  36. PUTS "a = " 0 WIDTH PUTSTACK PUTS "\n"
  37. 8 STO
  38. PUTS "b = " 0 WIDTH PUTSTACK PUTS "\n"
  39. 9 STO
  40. ; calculate RSQ = (a*sum(y) + b*sum(xy) - mean(sqr(sum(y))))/ (sum(sqr(y)) - mean(sqr(sum(y)))
  41. 8 RCL 2 RCL * 9 RCL 5 RCL * + 2 RCL SQR 6 RCL / DUP 0 STO - 4 RCL 0 RCL - /
  42. 4 FIX PUTS "RSQ = " 0 WIDTH PUTSTACK PUTS "\n"
  43. CLST
  44. END
  45.